// src/main/controller/LoggerController.ts
import { ipcMain } from 'electron';
import { loggerService } from '../service/LoggerService';

export function setupLoggerIPC() {
  const logHandler = (
    _event: Electron.IpcMainEvent,
    level: string,
    ...params: any[]
  ) => {
    try {
      loggerService.log(level, ...params);
    } catch (error) {
      loggerService.handleError(error);
    }
  };

  ipcMain.on('log', logHandler);

  return () => {
    ipcMain.removeListener('log', logHandler);
    loggerService.cleanupMessage();
  };
}
